package com.huarun.module.visitorApply.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.huarun.common.BaseServiceImpl;
import com.huarun.module.visitorApply.bean.VisitorApply;
import com.huarun.module.visitorApply.dao.VisitorApplyMapper;
import com.huarun.module.visitorApply.service.VisitorApplyService;
import java.util.Date;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;

@Service("VisitorApplyService")
public class VisitorApplyServiceImpl extends BaseServiceImpl<VisitorApplyMapper, VisitorApply>
  implements VisitorApplyService
{

  @Resource
  private VisitorApplyMapper visitorApplyMapper;

  @Override
  public PageInfo<Map<String, Object>> getMyApplyList(Map<String, Object> map, Integer page, Integer rows)
  {
    if (page == null) {
      page = Integer.valueOf(1);
    }
    if (rows == null) {
      rows = Integer.valueOf(10);
    }
    PageHelper.startPage(page.intValue(), rows.intValue());
    List<Map<String,Object>> myInvitedList = this.visitorApplyMapper.getMyApplyList(map);
    for (Map mapIn : myInvitedList) {
      Long createtime = (Long)mapIn.get("createDate");
      Long endTime = (Long)mapIn.get("endTime");
      Long startTime = (Long)mapIn.get("startTime");
      String status = (String)mapIn.get("status");
      long newTime = new Date().getTime() / 1000L;
      if (!status.equals("已取消")) {
        if (endTime.longValue() < newTime)
          mapIn.replace("statusCode", Integer.valueOf(3));
      }
      else {
        mapIn.replace("statusCode", Integer.valueOf(4));
      }
    }
    PageInfo pageInfo = new PageInfo(myInvitedList);
    return pageInfo;
  }

  @Override
  public Map<String, Object> getVisitorApplyId(Map<String, Object> map)
  {
    return this.visitorApplyMapper.getVisitorApplyId(map);
  }

  @Override
  public PageInfo<Map<String, Object>> getMyInvited(Map<String, Object> map, Integer page, Integer rows)
  {
    if (page == null) {
      page = Integer.valueOf(1);
    }
    if (rows == null) {
      rows = Integer.valueOf(10);
    }
    PageHelper.startPage(page.intValue(), rows.intValue());
    List<Map<String,Object>> myInvitedList = this.visitorApplyMapper.getMyInvited(map);
    for (Map<String,Object> mapIn : myInvitedList) {
      Long createtime = (Long)mapIn.get("createDate");
      Long endTime = (Long)mapIn.get("endTime");
      Long startTime = (Long)mapIn.get("startTime");
      long newTime = new Date().getTime() / 1000L;
      String status = (String)mapIn.get("status");
      if (!status.equals("已取消")) {
        if (endTime.longValue() < newTime) {
          mapIn.put("statusCode", Integer.valueOf(3));
        }
        else if (newTime < startTime.longValue())
          mapIn.put("statusCode", Integer.valueOf(5));
        else {
          mapIn.put("statusCode", Integer.valueOf(6));
        }
      }
      else
      {
        mapIn.put("statusCode", Integer.valueOf(4));
      }
    }
    PageInfo pageInfo = new PageInfo(myInvitedList);
    return pageInfo;
  }

  @Override
  public int cancelInviteId(Map<String, Object> map)
  {
    return this.visitorApplyMapper.cancelInviteId(map);
  }

  @Override
  public void updateCode(Map<String, Object> map)
  {
    this.visitorApplyMapper.updateCode(map);
  }

  @Override
  public Map<String, Object> findValidate(Map<String, Object> map)
  {
    return this.visitorApplyMapper.findValidate(map);
  }

  @Override
  public Map<String, Object> getDepartment(Map<String, Object> parames)
  {
    return this.visitorApplyMapper.getDepartment(parames);
  }
}

/* Location:           D:\msg\反编译\Webuilding-0.0.1-SNAPSHOT(5)\BOOT-INF\classes\
 * Qualified Name:     com.huarun.module.visitorApply.service.Impl.VisitorApplyServiceImpl
 * JD-Core Version:    0.6.2
 */